package com.crm.controller.adminController;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.crm.dao.AlertsDAO;
import com.crm.entity.Business;
import com.crm.entity.Opportunity;

@Controller
@RequestMapping("/adminhome")
public class adminHomeController {
	protected final Log logger = LogFactory.getLog(getClass());
	
	
	@RequestMapping("/open.do")
	public ModelAndView open(HttpSession session,ModelAndView model){
		Business bus=(Business)session.getAttribute("business");
		
		if(bus==null)return new ModelAndView("/jsp/index.jsp");
		
		model.setViewName("/jsp/client.jsp");
		model.addObject("submenu", "admin");
		model.addObject("menuName","admin");
		return model;
		
	}
	@RequestMapping("/alerts.do")
	public ModelAndView alerts(HttpSession session,ModelAndView model){
		Business bus=(Business)session.getAttribute("business");
		
		int busid=bus.getBusinessId();
		
		List<Opportunity> liop=new ArrayList<Opportunity>();
		try {
			liop=AlertsDAO.getSingleInstance().mainAlert(busid);
			System.out.println("the list size is"+liop.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.setViewName("/jsp/alerts.jsp");
		model.addObject("submenu", "admin");
		model.addObject("menuName","admin");
		model.addObject("oppList",liop);
		return model;
		
	}
	@RequestMapping("/errors.do")
	public ModelAndView errors(HttpSession session,ModelAndView model){
	System.out.println("hello we are in errror page code");
		model.setViewName("/jsp/pagenotfound.jsp");
		model.addObject("submenu", "admin");
		model.addObject("menuName","admin");
		
		return model;
		
	}
	@RequestMapping("/history.do")
	public ModelAndView historyPage(HttpSession session,ModelAndView model){
		model.setViewName("/jsp/history.jsp");
		model.addObject("submenu", "admin");
		model.addObject("menuName","admin");
		return model;
		
	}
	
}
